package everyday.luogu;

import java.util.Scanner;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/26/15:57
 * @Description:
 */
public class Num22 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int[] arr1 = new int[a];
        int[] arr2 = new int[b];
        while (scanner.hasNext()) {
            for (int i = 0; i < a; i++) {
                arr1[i] = scanner.nextInt();
            }
            for (int i = 0; i < b; i++) {
                arr2[i] = scanner.nextInt();
            }
            int c=a>b?a:b;
//            int[] arr3=new int[c];
//                for (int i = arr1.length-1; i >0 ; i--) {
//                    for (int  j = arr2.length-1; j >0 ; j--) {
//                        int ans=arr1[i]+arr2[j];
//                        int jw=2;
//                        int d=ans%jw;
//                        int e=ans/jw;
//                        arr1[i-1]=arr1[i-1]+e;
//                        jw++;
//                    }
//
//                }
            int[] arr3=new int[c];
            int i=arr1.length-1;
            int j=arr2.length-1;
            if(i>0 && j>0){
                int ans=arr1[i]+arr2[j];
                int jw=2;
                int d=ans%jw;
                int e=ans/jw;
                arr1[i-1]=arr1[i-1]+e;
                jw++;
                i--;
                j--;
                for (int k = c; k >=0; k--) {
                    arr3[k]=d;
                }
            }

            }
        }
//        System.out.println(arr1[a - 1]);
//        System.out.println(arr2[b - 1]);
//        for (int i = 0; i < a; i++) {
//            System.out.print(arr1[i]);
//        }
//        for (int i = 0; i < b; i++) {
//            System.out.print(arr2[i]);
//        }
    }
